package com.xique.park.controller.auto;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xique.common.log.annotation.Log;
import com.xique.common.log.enums.BusinessType;
import com.xique.common.security.annotation.PreAuthorize;
import com.xique.park.bean.domain.ParkIn;
import com.xique.park.service.service.IParkInService;
import com.xique.common.core.web.controller.BaseController;
import com.xique.common.core.web.domain.AjaxResult;
import com.xique.common.core.utils.poi.ExcelUtil;
import com.xique.common.core.web.page.TableDataInfo;

/**
 * 入场记录Controller
 * 
 * @author xique
 * @date 2021-12-09
 */
@RestController
@RequestMapping("/in")
public class ParkInController extends BaseController
{
    @Autowired
    private IParkInService parkInService;

    /**
     * 查询入场记录列表
     */
    @PreAuthorize(hasPermi = "park:in:list")
    @GetMapping("/list")
    public TableDataInfo list(ParkIn parkIn)
    {
        startPage();
        List<ParkIn> list = parkInService.selectParkInList(parkIn);
        return getDataTable(list);
    }

    /**
     * 导出入场记录列表
     */
    @PreAuthorize(hasPermi = "park:in:export")
    @Log(title = "入场记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ParkIn parkIn) throws IOException
    {
        List<ParkIn> list = parkInService.selectParkInList(parkIn);
        ExcelUtil<ParkIn> util = new ExcelUtil<ParkIn>(ParkIn.class);
        util.exportExcel(response, list, "入场记录数据");
    }

    /**
     * 获取入场记录详细信息
     */
    @PreAuthorize(hasPermi = "park:in:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(parkInService.selectParkInById(id));
    }

    /**
     * 新增入场记录
     */
    @PreAuthorize(hasPermi = "park:in:add")
    @Log(title = "入场记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ParkIn parkIn)
    {
        return toAjax(parkInService.insertParkIn(parkIn));
    }

    /**
     * 修改入场记录
     */
    @PreAuthorize(hasPermi = "park:in:edit")
    @Log(title = "入场记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ParkIn parkIn)
    {
        return toAjax(parkInService.updateParkIn(parkIn));
    }

    /**
     * 删除入场记录
     */
    @PreAuthorize(hasPermi = "park:in:remove")
    @Log(title = "入场记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(parkInService.deleteParkInByIds(ids));
    }
}
